

var vm = new Vue({
    el:"#app",
    data:{
        deptArea:'',
        parentDept:'',
        addFlag:''
    },
    methods:{
        getDeptArea:function () {
            axios.post("/dept/queryDeptArea").then(
                function(result){
                    vm.deptArea=result.data;
                    console.log(vm.deptArea);
                },function (err) {
                    console.log(err);
                }
            )
        },
        getDeptList:function () {
            axios.post("/dept/queryDeptListForAdd").then(
                function(result){
                    vm.parentDept=result.data;
                    console.log(vm.parentDept);
                },function (err) {
                    console.log(err);
                }
            )
        },
        addDept:function (){
            let flag = true;
            let deptName = $("input[name='deptName']").val();
            if (deptName === ""){
                flag = false;
            }
            let deptArea = $(".deptArea").val();
            if (deptArea === "请选择"){
                flag = false;
            }
            let parentDept = $(".parentDept").val();
            if (parentDept === "请选择"){
                flag = false;
            }
            if (flag){
                axios.post("/dept/addDept",{deptName:deptName,deptArea:deptArea,deptFName:parentDept}).then(
                    function(result){
                        vm.addFlag = result.data;
                        console.log(vm.addFlag);
                        if (vm.addFlag){
                            alert("添加部门成功");
                            location.href = "../../../../templates/sysManage/deptManage/deptList.html";
                        }else {
                            alert("添加部门失败");
                        }
                    },function (err) {
                        console.log(err);
                    }
                )
            }else {
                alert("您的信息还未填写完全");
            }
        }
    },
    //页面加载完自动执行
    mounted(){
        this.getDeptList();
        this.getDeptArea();
    }
})
